package com.example.goodpet.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.layout.StaggeredGridLayoutHelper;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.example.goodpet.R;
import com.example.goodpet.commentdialog.bean.CommentEntity;
import com.example.goodpet.commentdialog.bean.CommentMoreBean;
import com.example.goodpet.commentdialog.bean.FirstLevelBean;
import com.example.goodpet.commentdialog.bean.SecondLevelBean;
import com.example.goodpet.commentdialog.bean.TieziCommentFirst;
import com.example.goodpet.commentdialog.bean.TieziCommentSecond;
import com.example.goodpet.commentdialog.dialog.InputTextMsgDialog;
import com.example.goodpet.commentdialog.listener.SoftKeyBoardListener;
import com.example.goodpet.commentdialog.multi.CommentDialogAdapter;
import com.example.goodpet.commentdialog.util.RecyclerViewUtil;
import com.example.goodpet.db.DatabaseHelper;
import com.example.goodpet.db.dao.UserDAO;
import com.example.goodpet.db.entity.TieziHistory;
import com.example.goodpet.db.entity.User;
import com.example.goodpet.utils.ActivityManager;
import com.example.goodpet.utils.MyApplication;
import com.example.goodpet.activity.adapter.PetInfoImageAdapter;
import com.example.goodpet.bean.Follow;
import com.example.goodpet.bean.ResponseBody;
import com.example.goodpet.bean.UserPetInfo;
import com.example.goodpet.common.EndlessRecyclerOnScrollListener;
import com.example.goodpet.common.LoadMoreWrapper;
import com.example.goodpet.community.adapter.CommunityRecyclerViewAdapter;
import com.example.goodpet.community.bean.UserTieziInfo;
import com.example.goodpet.service.HomeService;
import com.example.goodpet.service.UserService;
import com.example.goodpet.utils.Constants;
import com.example.goodpet.utils.RetrofitSingleton;
import com.example.goodpet.utils.TimeSeed;
import com.example.goodpet.utils.UIUtils;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;

import java.sql.Date;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class TieziInfoActivity extends FragmentActivity implements View.OnClickListener, BaseQuickAdapter.RequestLoadMoreListener{
    private final int REQ_USER_INFO=100;

    private String TAG=this.getClass().getSimpleName();

    private ImageButton ibTieziInfoBack;
    private CircleImageView ivTieziInfoReleasePortrait;
    private TextView tvTieziInfoReleaseUser;
    private TextView btnTieziInfoFocus;
    private ImageButton ibTieziInfoMore;
    private RecyclerView rvTieziInfoImage;
    private TextView tvTieziInfoDesc;
    private TextView tvTieziInfoTime;
    private ImageView tieziCollect;
    private TextView tieziCollectNumber;
    private ImageView tieziLiuyan;
    private TextView tieziLiuyanNumber;
    private ImageView tieziLike;
    private TextView tieziLikeNumber;
    private RecyclerView rvTieziInfoMore;

    private UserTieziInfo userTieziInfo;

    private UserService userService;
    private int POSITION;

    private Retrofit retrofit;
    private HomeService homeService;
    private long seed= TimeSeed.Get();
    private UserDAO userDAO;

    private List<UserTieziInfo> userTieziInfos;
    //VLayout
    private VirtualLayoutManager layoutManager;
    //主页上方适配器集合
    private List<DelegateAdapter.Adapter> subAdapters = new LinkedList();


    private int PAGE;
    private int[] page=new int[0];
    private int SIZE=10;

    private List<MultiItemEntity> data = new ArrayList<>();
    private List<FirstLevelBean> datas = new ArrayList<>();
    private BottomSheetDialog bottomSheetDialog;
    private InputTextMsgDialog inputTextMsgDialog;
    private float slideOffset = 0;
    private CommentDialogAdapter bottomSheetAdapter;
    private RecyclerView rv_dialog_lists;
    private long totalCount = 0;
    private int offsetY;
    private int positionCount = 0;
    private RecyclerViewUtil mRecyclerViewUtil;
    private SoftKeyBoardListener mKeyBoardListener;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tiezi_info);

        UltimateBarX.statusBarOnly(this)
                .fitWindow(true)
                .colorRes(R.color.ic_back_background)
                .light(true)
                .apply();
        ActivityManager.getInstance().addActivity(this);

        userTieziInfo=getIntent().getParcelableExtra("userTieziInfo");
        POSITION = getIntent().getIntExtra("position", -1);

        retrofit=RetrofitSingleton.getRetrofitConstance();
        homeService=retrofit.create(HomeService.class);
        userService=retrofit.create(UserService.class);
        findViews();

        //将浏览记录加入本地数据库
        TieziHistory tieziHistory = new TieziHistory();
        tieziHistory.setTieziId(userTieziInfo.getTieziId());
        tieziHistory.setUserId(MyApplication.user.getId());
        tieziHistory.setPostdate(new Date(System.currentTimeMillis()).toString());
        DatabaseHelper.getInstance(this).getTieziHistoryDAO().insert(tieziHistory);
        //记录或更新该页面展示的用户在本地数据库中的信息
        recordUser();
        if(userTieziInfo!=null){
            Log.e(TAG, "onCreate: "+userTieziInfo.getTieziId() );
            initData();

            //初始化留言数据
            mRecyclerViewUtil = new RecyclerViewUtil();
            initCommentData();
        }

    }



    private void initRefresh() {
        PAGE=1;
        datas.clear();
        initCommentData();
        dataSort(0);
        bottomSheetAdapter.setNewData(data);
    }

    //原始数据 一般是从服务器接口请求过来的
    private void initCommentData() {
        homeService.selectTieziCommentCount( userTieziInfo.getTieziId())
                .enqueue(new Callback<ResponseBody<Integer>>() {
                    @Override
                    public void onResponse(Call<ResponseBody<Integer>> call, Response<ResponseBody<Integer>> response) {
                        ResponseBody<Integer> body = response.body();
                        if(body.getCode()==200){
                            totalCount=body.getData();
                            page=new int[(int) totalCount];
                            initNext();
                        }else{
                            UIUtils.toast("评论数获取失败",false);
                        }
                    }

                    private void initNext() {
                        homeService.selectTieziComment(MyApplication.user.getId(),userTieziInfo.getTieziId(),1)
                                .enqueue(new Callback<ResponseBody<List<FirstLevelBean>>>() {
                                    @Override
                                    public void onResponse(Call<ResponseBody<List<FirstLevelBean>>> call, Response<ResponseBody<List<FirstLevelBean>>> response) {
                                        ResponseBody<List<FirstLevelBean>> body = response.body();
                                        if(body.getCode()==200){

                                            //后端需要获取除positionCount外的所有数据！！！！！！！！！！！

                                            List<FirstLevelBean> data1 = body.getData();
                                            if(null!=data1){
                                                for (FirstLevelBean datum : data1) {
                                                    page[datum.getPosition()]=1;
                                                    datum.setSecondLevelBeans(new ArrayList<>());
                                                }
                                                datas.addAll(data1);
//                                Log.e(TAG, "onResponse: "+data1);
                                            }

                                        }else{
                                            UIUtils.toast("暂无更多评论",false);
                                        }
                                        dataSort(0);
                                        showSheetDialog();
                                    }

                                    @Override
                                    public void onFailure(Call<ResponseBody<List<FirstLevelBean>>> call, Throwable t) {
                                        UIUtils.toast("网络通信失败",false);
                                    }
                                });
                    }

                    @Override
                    public void onFailure(Call<ResponseBody<Integer>> call, Throwable t) {
                        UIUtils.toast("连接服务器失败",false);
                    }
                });



    }

    /**
     * 对数据重新进行排列
     * 目的是为了让一级评论和二级评论同为item
     * 解决滑动卡顿问题
     *
     * @param position
     */
    private void dataSort(int position) {

        if (datas.isEmpty()) {
            data.add(new MultiItemEntity() {
                @Override
                public int getItemType() {
                    return CommentEntity.TYPE_COMMENT_EMPTY;
                }
            });
            return;
        }

        if (position <= 0) data.clear();
        int posCount = data.size();
        int count = datas.size();
        for (int i = 0; i < count; i++) {
            if (i < position) continue;

            //一级评论
            FirstLevelBean firstLevelBean = datas.get(i);
            if (firstLevelBean == null) continue;
            firstLevelBean.setPosition(i);
            posCount += 2;
            List<SecondLevelBean> secondLevelBeans = firstLevelBean.getSecondLevelBeans();
//            Log.e(TAG, "dataSort: "+secondLevelBeans );
//
            int beanSize = secondLevelBeans.size();
            //如果当前一级评论内二级评论的数据已经获取完毕，则不需要再有更多的点击
            if (firstLevelBean.getTotalCount()==beanSize+1) {
                //如果获取完二级评论数据后，发现并没有二级评论，直接跳
                if(firstLevelBean.getTotalCount()==1){
                    firstLevelBean.setPositionCount(posCount);
                    data.add(firstLevelBean);
                    continue;
                }
            }
            //有二级评论，把数据加上去
            posCount += beanSize;
            firstLevelBean.setPositionCount(posCount);
            data.add(firstLevelBean);

            //二级评论
            for (int j = 0; j < beanSize; j++) {
                SecondLevelBean secondLevelBean = secondLevelBeans.get(j);
                secondLevelBean.setChildPosition(j);
                secondLevelBean.setPosition(i);
                secondLevelBean.setPositionCount(posCount);
                data.add(secondLevelBean);
            }
//            Log.e(TAG, "dataSort: "+beanSize );
            //展示更多的item
//            Log.e(TAG, "dataSort: "+firstLevelBean.getTotalCount() );
            if (beanSize+1 < firstLevelBean.getTotalCount()) {
                CommentMoreBean moreBean = new CommentMoreBean();
                moreBean.setPosition(i);
                moreBean.setPositionCount(posCount);
                moreBean.setTotalCount(firstLevelBean.getTotalCount());
                data.add(moreBean);
            }

        }
    }

    public void show() {
        for (int i = 0; i < page.length; i++) {
            page[i]=1;
        }
//        for(String key : mapPage.keySet()){
//            mapPage.put(key,1);
//        }
        bottomSheetAdapter.notifyDataSetChanged();
        slideOffset = 0;
        bottomSheetDialog.show();
    }


    private void showSheetDialog() {
        if (bottomSheetDialog != null) {
            return;
        }

        //view
        View view = View.inflate(this, R.layout.dialog_bottomsheet, null);
        ImageView iv_dialog_close = (ImageView) view.findViewById(R.id.dialog_bottomsheet_iv_close);
        rv_dialog_lists = (RecyclerView) view.findViewById(R.id.dialog_bottomsheet_rv_lists);
        RelativeLayout rl_comment = view.findViewById(R.id.rl_comment);
        iv_dialog_close.setOnClickListener(v -> bottomSheetDialog.dismiss());
        rl_comment.setOnClickListener(v -> {
            //添加二级评论
            initInputTextMsgDialog(null, false, null, -1);
        });

        //adapter
        bottomSheetAdapter = new CommentDialogAdapter(data);
        rv_dialog_lists.setHasFixedSize(true);
        rv_dialog_lists.setLayoutManager(new LinearLayoutManager(this));
        closeDefaultAnimator(rv_dialog_lists);
        bottomSheetAdapter.setOnLoadMoreListener(this, rv_dialog_lists);
        rv_dialog_lists.setAdapter(bottomSheetAdapter);

        //dialog
        bottomSheetDialog = new BottomSheetDialog(this, R.style.dialog);
        bottomSheetDialog.setContentView(view);
        bottomSheetDialog.setCanceledOnTouchOutside(true);
        BottomSheetBehavior mDialogBehavior = BottomSheetBehavior.from((View) view.getParent());
        mDialogBehavior.setPeekHeight(getWindowHeight());
        //dialog滑动监听
        mDialogBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                    mDialogBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                } else if (newState == BottomSheetBehavior.STATE_SETTLING) {
                    if (slideOffset <= -0.28) {
                        //当向下滑动时 值为负数

                        bottomSheetDialog.dismiss();
                    }
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                TieziInfoActivity.this.slideOffset = slideOffset;//记录滑动值
            }
        });

        initListener();
    }

    private void initListener() {

        for (int i = 0; i < page.length; i++) {
            page[i]=1;
        }
        // 点击事件
        bottomSheetAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view1, int position) {
                switch ((int) view1.getTag()) {
                    case CommentEntity.TYPE_COMMENT_PARENT:
                        if (view1.getId() == R.id.rl_group) {
                            //添加二级评论
                            TieziInfoActivity.this.initInputTextMsgDialog((View) view1.getParent(), false, bottomSheetAdapter.getData().get(position), position);
                        } else if (view1.getId() == R.id.ll_like) {
                            //一级评论点赞 项目中还得通知服务器 成功才可以修改
                            FirstLevelBean bean = (FirstLevelBean) bottomSheetAdapter.getData().get(position);
                            if(bean.getId()!=0){
                                homeService.tieziCommentLike(MyApplication.user.getId(), bean.getId())
                                        .enqueue(new Callback<ResponseBody<Integer>>() {
                                            @Override
                                            public void onResponse(Call<ResponseBody<Integer>> call, Response<ResponseBody<Integer>> response) {
                                                ResponseBody<Integer> body = response.body();
                                                if(body.getCode()==200) {
                                                    if (body.getData() > 0) {
                                                        bean.setLikeCount(bean.getLikeCount() + (bean.getIsLike() == 0 ? 1 : -1));
                                                        bean.setIsLike(bean.getIsLike() == 0 ? 1 : 0);
                                                        datas.set(bean.getPosition(), bean);
                                                        TieziInfoActivity.this.dataSort(0);
                                                        bottomSheetAdapter.notifyDataSetChanged();
                                                    } else {
                                                        UIUtils.toast("点赞失败", false);
                                                    }
                                                }else if(body.getCode()==404){
                                                    UIUtils.toast("点赞失败 404",false);
                                                }
                                            }

                                            @Override
                                            public void onFailure(Call<ResponseBody<Integer>> call, Throwable t) {
                                                UIUtils.toast("连接服务器失败，点赞失败",false);
                                            }
                                        });
                            }else{
                                UIUtils.toast("操作过快",false);
                            }


                        }
                        break;
                    case CommentEntity.TYPE_COMMENT_CHILD:

                        if (view1.getId() == R.id.rl_group) {
                            //添加二级评论（回复）
                            TieziInfoActivity.this.initInputTextMsgDialog(view1, true, bottomSheetAdapter.getData().get(position), position);
                        } else if (view1.getId() == R.id.ll_like) {
                            //二级评论点赞 项目中还得通知服务器 成功才可以修改
                            SecondLevelBean bean = (SecondLevelBean) bottomSheetAdapter.getData().get(position);
                            homeService.tieziCommentLikeSecond(MyApplication.user.getId(),bean.getId())
                                    .enqueue(new Callback<ResponseBody<Integer>>() {
                                        @Override
                                        public void onResponse(Call<ResponseBody<Integer>> call, Response<ResponseBody<Integer>> response) {
                                            ResponseBody<Integer> body = response.body();
                                            if(body.getCode()==200){
                                                if(body.getData()>0){
                                                    bean.setLikeCount(bean.getLikeCount() + (bean.getIsLike() == 0 ? 1 : -1));
                                                    bean.setIsLike(bean.getIsLike() == 0 ? 1 : 0);

                                                    List<SecondLevelBean> secondLevelBeans = datas.get((int) bean.getPosition()).getSecondLevelBeans();
                                                    secondLevelBeans.set(bean.getChildPosition(), bean);
//                            CommentMultiActivity.this.dataSort(0);
                                                    bottomSheetAdapter.notifyDataSetChanged();
                                                }else{
                                                    UIUtils.toast("点赞失败", false);
                                                }
                                            }else if(body.getCode()==404){
                                                UIUtils.toast("点赞失败 404", false);
                                            }
                                        }

                                        @Override
                                        public void onFailure(Call<ResponseBody<Integer>> call, Throwable t) {
                                            UIUtils.toast("连接服务器失败，点赞失败",false);
                                        }
                                    });

                        }

                        break;
                    case CommentEntity.TYPE_COMMENT_MORE:
                        //在项目中是从服务器获取数据，其实就是二级评论分页获取，同样获取很多数据。。。。
                        CommentMoreBean moreBean = (CommentMoreBean) bottomSheetAdapter.getData().get(position);

                        int positon=(int) moreBean.getPosition();
                        //根据位置获取firstId
                        long firstId = datas.get(positon).getId();
                        //根据firstId获取当前页码
//                        int page = mapPage.get(String.valueOf(id));
                        homeService.selectTieziCommentSecond(MyApplication.user.getId(),firstId,page[positon])
                                .enqueue(new Callback<ResponseBody<List<SecondLevelBean>>>() {
                                    @Override
                                    public void onResponse(Call<ResponseBody<List<SecondLevelBean>>> call, Response<ResponseBody<List<SecondLevelBean>>> response) {
                                        ResponseBody<List<SecondLevelBean>> body = response.body();
                                        if(body.getCode()==200){
                                            List<SecondLevelBean> data = body.getData();
                                            if(null!=data){
                                                datas.get((int) moreBean.getPosition()).getSecondLevelBeans().addAll(data);
                                                TieziInfoActivity.this.dataSort(0);
                                                bottomSheetAdapter.notifyDataSetChanged();
                                            }else{
                                                UIUtils.toast("获取评论数据失败",false);
                                            }

                                        }else if(body.getCode()==404){
                                            UIUtils.toast("获取评论数据失败 404",false);
                                        }
                                    }

                                    @Override
                                    public void onFailure(Call<ResponseBody<List<SecondLevelBean>>> call, Throwable t) {
                                        UIUtils.toast("连接服务器失败，获取评论数据失败",false);
                                    }
                                });
                        page[positon]++;
//                        page++;
//                        mapPage.put(String.valueOf(id),page);
                        break;
                    case CommentEntity.TYPE_COMMENT_EMPTY:
                        TieziInfoActivity.this.initRefresh();
                        break;

                }

            }
        });
        //滚动事件
        if (mRecyclerViewUtil != null) mRecyclerViewUtil.initScrollListener(rv_dialog_lists);

        mKeyBoardListener = new SoftKeyBoardListener(this, new SoftKeyBoardListener.OnSoftKeyBoardChangeListener() {
            @Override
            public void keyBoardShow(int height) {
            }

            @Override
            public void keyBoardHide(int height) {
                dismissInputDialog();
            }
        });
    }

    private void initInputTextMsgDialog(View view, final boolean isReply, final MultiItemEntity item, final int position) {
        dismissInputDialog();
        if (view != null) {
            offsetY = view.getTop();
            scrollLocation(offsetY);
        }
        if (inputTextMsgDialog == null) {
            inputTextMsgDialog = new InputTextMsgDialog(this, R.style.dialog);
            inputTextMsgDialog.setmOnTextSendListener(new InputTextMsgDialog.OnTextSendListener() {
                @Override
                public void onTextSend(String msg) {
                    addComment(isReply, item, position, msg);
                }

                @Override
                public void dismiss() {
                    //item滑动到原位
                    scrollLocation(-offsetY);
                }
            });
        }
        showInputTextMsgDialog();
    }

    //添加评论
    private void addComment(boolean isReply, MultiItemEntity item, final int position, String msg) {
        final String userName = MyApplication.user.getNickname();
        if (position >= 0) {
            //添加二级评论
            int pos = 0;
            String replyUserName = "未知";
            long replyUserId = MyApplication.user.getId();
            if (item instanceof FirstLevelBean) {
                FirstLevelBean firstLevelBean = (FirstLevelBean) item;
                positionCount = (int) (firstLevelBean.getPositionCount() + 1);
                pos = (int) firstLevelBean.getPosition();
                replyUserName = firstLevelBean.getUserName();
                replyUserId = firstLevelBean.getUserId()==0?replyUserId:firstLevelBean.getUserId();
            } else if (item instanceof SecondLevelBean) {
                SecondLevelBean secondLevelBean = (SecondLevelBean) item;
                positionCount = (int) (secondLevelBean.getPositionCount() + 1);
                pos = (int) secondLevelBean.getPosition();
                replyUserName = secondLevelBean.getUserName();
                replyUserId = secondLevelBean.getUserId()==0?replyUserId:secondLevelBean.getUserId();
            }
                //进行服务器端的操作，将二级评论添加至数据库
                TieziCommentSecond tieziCommentSecond=new TieziCommentSecond();
                tieziCommentSecond.setReplyUserName(replyUserName);
                tieziCommentSecond.setReplyUserId(replyUserId);
                tieziCommentSecond.setIsReply(isReply ? 1 : 0);
                tieziCommentSecond.setContent(msg);
                tieziCommentSecond.setLikeCount(0);
                tieziCommentSecond.setCreateTime(System.currentTimeMillis());
                tieziCommentSecond.setSenderId(MyApplication.user.getId());
//                Log.e(TAG, "addComment: "+ datas.get(pos).getId());
                tieziCommentSecond.setFirstId(datas.get(pos).getId());
                int finalPos = pos;
                homeService.insertTieziCommentSecond(tieziCommentSecond)
                        .enqueue(new Callback<ResponseBody<TieziCommentSecond>>() {
                            @Override
                            public void onResponse(Call<ResponseBody<TieziCommentSecond>> call, Response<ResponseBody<TieziCommentSecond>> response) {
                                ResponseBody<TieziCommentSecond> body = response.body();
                                if(body.getCode()==200){
                                    if(body.getData()!=null){
                                        UIUtils.toast("留言成功",false);
                                        initNext(body.getData());
                                    }else{
                                        UIUtils.toast("留言失败", false);
                                    }
                                }else if(body.getCode()==404){
                                    UIUtils.toast("留言同步失败 404", false);
                                }
                            }

                            private void initNext(TieziCommentSecond data2) {
                                SecondLevelBean secondLevelBean = new SecondLevelBean();
                                secondLevelBean.setReplyUserName(data2.getReplyUserName());
                                secondLevelBean.setIsReply((int) data2.getIsReply());
                                secondLevelBean.setContent(data2.getContent());
                                secondLevelBean.setHeadImg(MyApplication.user.getPortrait());
                                secondLevelBean.setCreateTime(data2.getCreateTime());
                                secondLevelBean.setIsLike(0);
                                secondLevelBean.setUserName(userName);
                                secondLevelBean.setId(data2.getId());
                                secondLevelBean.setPosition(positionCount);

                                datas.get(finalPos).getSecondLevelBeans().add(secondLevelBean);
                                TieziInfoActivity.this.dataSort(0);
                                bottomSheetAdapter.notifyDataSetChanged();
                                rv_dialog_lists.postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        ((LinearLayoutManager) rv_dialog_lists.getLayoutManager())
                                                .scrollToPositionWithOffset(positionCount >= data.size() - 1 ? data.size() - 1
                                                        : positionCount, positionCount >= data.size() - 1 ? Integer.MIN_VALUE : rv_dialog_lists.getHeight());
                                    }
                                }, 100);
                            }

                            @Override
                            public void onFailure(Call<ResponseBody<TieziCommentSecond>> call, Throwable t) {
                                UIUtils.toast("连接服务器失败，留言失败",false);
                            }
                        });






        } else {
            //添加一级评论

            //进行服务器端的操作，将一级评论添加至数据库
            TieziCommentFirst tieziCommentFirst=new TieziCommentFirst();
            tieziCommentFirst.setTieziId(userTieziInfo.getTieziId());
            tieziCommentFirst.setSenderId(MyApplication.user.getId());
            tieziCommentFirst.setContent(msg);
            tieziCommentFirst.setLikeCount(0);
            tieziCommentFirst.setCreateTime(System.currentTimeMillis());
            homeService.insertTieziComment(tieziCommentFirst)
                    .enqueue(new Callback<ResponseBody<TieziCommentFirst>>() {
                        @Override
                        public void onResponse(Call<ResponseBody<TieziCommentFirst>> call, Response<ResponseBody<TieziCommentFirst>> response) {
                            ResponseBody<TieziCommentFirst> body = response.body();
                            if(body.getCode()==200){
                                if(body.getData()!=null){
                                    UIUtils.toast("评论成功",false);
                                    initNext(body.getData());
                                }else{
                                    UIUtils.toast("评论失败",false);
                                }
                            }else{
                                UIUtils.toast("评论失败 404",false);
                            }
                        }

                        private void initNext(TieziCommentFirst data1) {
                            userTieziInfo.setMessageNum(userTieziInfo.getMessageNum()+1);
                            Intent intent = new Intent();
                            intent.putExtra("info",userTieziInfo);
                            intent.putExtra("position",POSITION);

                            setResult(RESULT_OK,intent);
                            //更新显示的数量
                            tieziLiuyanNumber.setText(String.valueOf(userTieziInfo.getMessageNum()));


                            FirstLevelBean firstLevelBean = new FirstLevelBean();
                            firstLevelBean.setUserName(userName);
                            firstLevelBean.setId(data1.getId());
                            firstLevelBean.setHeadImg(MyApplication.user.getPortrait());
                            firstLevelBean.setCreateTime(data1.getCreateTime());
                            firstLevelBean.setContent(data1.getContent());
                            firstLevelBean.setLikeCount(data1.getLikeCount());
                            firstLevelBean.setSecondLevelBeans(new ArrayList<SecondLevelBean>());
                            datas.add(0, firstLevelBean);
                            TieziInfoActivity.this.dataSort(0);
                            bottomSheetAdapter.notifyDataSetChanged();
                            rv_dialog_lists.scrollToPosition(0);
                        }

                        @Override
                        public void onFailure(Call<ResponseBody<TieziCommentFirst>> call, Throwable t) {
                            UIUtils.toast("连接服务器失败，一级评论失败",false);
                        }
                    });




        }
    }

    private void dismissInputDialog() {
        if (inputTextMsgDialog != null) {
            if (inputTextMsgDialog.isShowing()) inputTextMsgDialog.dismiss();
            inputTextMsgDialog.cancel();
            inputTextMsgDialog = null;
        }
    }

    private void showInputTextMsgDialog() {
        inputTextMsgDialog.show();
    }

    private int getWindowHeight() {
        Resources res = getResources();
        DisplayMetrics displayMetrics = res.getDisplayMetrics();
        return displayMetrics.heightPixels;
    }

    @Override
    public void onLoadMoreRequested() {
        if (datas.size() >= totalCount) {
            bottomSheetAdapter.loadMoreEnd(false);
            return;
        }
        homeService.selectTieziComment(MyApplication.user.getId(),userTieziInfo.getTieziId(),++PAGE)
                .enqueue(new Callback<ResponseBody<List<FirstLevelBean>>>() {
                    @Override
                    public void onResponse(Call<ResponseBody<List<FirstLevelBean>>> call, Response<ResponseBody<List<FirstLevelBean>>> response) {
                        ResponseBody<List<FirstLevelBean>> body = response.body();
                        if(body.getCode()==200){
                            List<FirstLevelBean> data = body.getData();
                            if(null!=data){
                                for (FirstLevelBean datum : data) {
//                                    String s = String.valueOf(datum.getId());
//                                    mapPage.put(s,1);
                                    datum.setSecondLevelBeans(new ArrayList<>());
                                }
                                datas.addAll(data);
                            }
                            dataSort(datas.size() - SIZE);
                            bottomSheetAdapter.notifyDataSetChanged();
                            bottomSheetAdapter.loadMoreComplete();
                        }else if(body.getCode()==404){
                            UIUtils.toast("没有更多评论啦~",false);
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody<List<FirstLevelBean>>> call, Throwable t) {
                        UIUtils.toast("连接服务器失败，获取评论失败",false);
                    }
                });
    }

    // item滑动
    public void scrollLocation(int offsetY) {
        try {
            rv_dialog_lists.smoothScrollBy(0, offsetY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 关闭默认局部刷新动画
     */
    public void closeDefaultAnimator(RecyclerView mRvCustomer) {
        if (null == mRvCustomer) return;
        mRvCustomer.getItemAnimator().setAddDuration(0);
        mRvCustomer.getItemAnimator().setChangeDuration(0);
        mRvCustomer.getItemAnimator().setMoveDuration(0);
        mRvCustomer.getItemAnimator().setRemoveDuration(0);
        ((SimpleItemAnimator) mRvCustomer.getItemAnimator()).setSupportsChangeAnimations(false);
    }

    @Override
    protected void onDestroy() {
        if (mRecyclerViewUtil != null){
            mRecyclerViewUtil.destroy();
            mRecyclerViewUtil = null;
        }
        if (mKeyBoardListener != null) {
            mKeyBoardListener.setOnSoftKeyBoardChangeListener(null);
            mKeyBoardListener = null;
        }
        bottomSheetAdapter = null;
        super.onDestroy();
    }


    /**
     * 记录user到sqlite数据库
     */
    private void recordUser() {
        userDAO = DatabaseHelper.getInstance(this).getUserDAO();
        User user = new User(userTieziInfo.getUserId(),userTieziInfo.getPhoneNumber(),userTieziInfo.getNickname(),userTieziInfo.getPortrait(),(int)userTieziInfo.getGender(),userTieziInfo.getSignature());
        userDAO.insert(user);
    }
    /**
     * Find the Views in the layout<br />
     * <br />
     * Auto-created on 2022-09-06 20:37:25 by Android Layout Finder
     * (http://www.buzzingandroid.com/tools/android-layout-finder)
     */
    private void findViews() {
        ibTieziInfoBack = (ImageButton)findViewById( R.id.ib_tiezi_info_back );
        ivTieziInfoReleasePortrait = (CircleImageView)findViewById( R.id.iv_tiezi_info_releasePortrait );
        tvTieziInfoReleaseUser = (TextView)findViewById( R.id.tv_tiezi_info_releaseUser );
        btnTieziInfoFocus = (TextView)findViewById( R.id.btn_tiezi_info_focus );
        ibTieziInfoMore = (ImageButton)findViewById( R.id.ib_tiezi_info_more );
        rvTieziInfoImage = (RecyclerView)findViewById( R.id.rv_tiezi_info_image );
        tvTieziInfoDesc = (TextView)findViewById( R.id.tv_tiezi_info_desc );
        tvTieziInfoTime = (TextView)findViewById( R.id.tv_tiezi_info_time );
        tieziCollect = (ImageView)findViewById( R.id.tiezi_collect );
        tieziCollectNumber = (TextView)findViewById( R.id.tiezi_collect_number );
        tieziLiuyan = (ImageView)findViewById( R.id.tiezi_liuyan );
        tieziLiuyanNumber = (TextView)findViewById( R.id.tiezi_liuyan_number );
        tieziLike = (ImageView)findViewById( R.id.tiezi_like );
        tieziLikeNumber = (TextView)findViewById( R.id.tiezi_like_number );
        rvTieziInfoMore = (RecyclerView)findViewById( R.id.rv_tiezi_info_more );

        ibTieziInfoBack.setOnClickListener( this );
        ibTieziInfoMore.setOnClickListener( this );
        ivTieziInfoReleasePortrait.setOnClickListener( this );
        tvTieziInfoReleaseUser.setOnClickListener( this );
        tieziCollect.setOnClickListener(this);
        tvTieziInfoReleaseUser.setOnClickListener(this);
        btnTieziInfoFocus.setOnClickListener(this);
        tieziCollectNumber.setOnClickListener(this);
        tieziLiuyan.setOnClickListener(this);
        tieziLiuyanNumber.setOnClickListener(this);
        tieziLike.setOnClickListener(this);
        tieziLikeNumber.setOnClickListener(this);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        ActivityManager.getInstance().removeCurrent();
    }

    /**
     * Handle button click events<br />
     * <br />
     * Auto-created on 2022-09-06 20:37:25 by Android Layout Finder
     * (http://www.buzzingandroid.com/tools/android-layout-finder)
     */
    @Override
    public void onClick(View v) {
        if ( v == ibTieziInfoBack ) {
            // Handle clicks for ibTieziInfoBack
            onBackPressed();
        } else if ( v == ibTieziInfoMore ) {
            UIUtils.toast("更多",false);
            // Handle clicks for ibTieziInfoMore
        } else if( v ==ivTieziInfoReleasePortrait || v==tvTieziInfoReleaseUser){
            //打开发布帖子用户主页
            if (MyApplication.user==null) actionToLoginAC();
            else {
                Intent intent = new Intent(this, UserInfoActivity.class);
                UserPetInfo userPetInfo = new UserPetInfo();
                userPetInfo.setUserId(userTieziInfo.getUserId());
                userPetInfo.setGender(userTieziInfo.getGender());
                userPetInfo.setPortrait(userTieziInfo.getPortrait());
                userPetInfo.setPhoneNumber(userTieziInfo.getPhoneNumber());
                userPetInfo.setSignature(userTieziInfo.getSignature());
                userPetInfo.setNickname(userTieziInfo.getNickname());
                intent.putExtra("user",userPetInfo);
                startActivityForResult(intent,REQ_USER_INFO);
            }
        }else if( v==btnTieziInfoFocus){
            if (MyApplication.user==null) actionToLoginAC();
            else {
                JudgeFollowRequest();
            }
        }else if(v==tieziLiuyan || v== tieziLiuyanNumber){
            if (MyApplication.user==null) actionToLoginAC();
            else{
                //打开留言列表
                PAGE=1;
                show();
            }
        }else if(v==tieziLike || v==tieziLikeNumber){
            //给帖子点赞
            if (MyApplication.user==null) actionToLoginAC();
            else {
//                UIUtils.toast("点赞",false);
                 initLikeClickListener();
            }
        }else if(v==tieziCollect || v==tieziCollectNumber){
            //收藏帖子
            // Handle clicks for btnPetInfoConsult
            if (MyApplication.user==null) actionToLoginAC();
            else {
//                UIUtils.toast("收藏",false);
                initCollectClickListener();
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK){
            if (requestCode==REQ_USER_INFO){
                //更新关注数据
                if (userTieziInfo.isFoucs()){
                    btnTieziInfoFocus.setCompoundDrawablesWithIntrinsicBounds(getDrawable(R.drawable.add16),null,null,null);
                    btnTieziInfoFocus.setText("关注");
                    userTieziInfo.setFoucs(false);
                }else {
                    btnTieziInfoFocus.setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);
                    btnTieziInfoFocus.setText("取消关注");
                    userTieziInfo.setFoucs(true);
                }
            }
        }
    }

    /**
     * 判断应该发送关注请求请求还是取消关注请求，并发送请求
     */
    private void JudgeFollowRequest() {
        if (userTieziInfo.isFoucs()){
            new AlertDialog.Builder(this)
                    .setTitle("温馨提示")
                    .setMessage("您确定要取消关注吗？")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //连接服务器,传送用户id
                            userService.unFollowSomeone(new Follow(0, MyApplication.user.getId(),userTieziInfo.getUserId(), null)).enqueue(new Callback<com.example.goodpet.bean.ResponseBody<Object>>() {
                                @Override
                                public void onResponse(Call<com.example.goodpet.bean.ResponseBody<Object>> call, Response<com.example.goodpet.bean.ResponseBody<Object>> response) {
                                    com.example.goodpet.bean.ResponseBody<Object> body = response.body();
                                    if (body!=null){
                                        int code = body.getCode();
                                        if (code==200){
                                            userTieziInfo.setFoucs(false);
                                            btnTieziInfoFocus.setText("关注");
                                            Intent intent = new Intent();
                                            intent.putExtra("info",userTieziInfo);
                                            intent.putExtra("position",POSITION);

                                            setResult(RESULT_OK,intent);
                                        }else if (code==500){
                                            UIUtils.toast("服务器发生错误",false);
                                        }
                                    }
                                }

                                @Override
                                public void onFailure(Call<com.example.goodpet.bean.ResponseBody<Object>> call, Throwable t) {
                                    UIUtils.toast("连接服务器失败",false);
                                }
                            });

                        }
                    })
                    .setNegativeButton("点错了", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    })
                    .setCancelable(false).show();
        }else if (!userTieziInfo.isFoucs()){
            userService.followSomeone(new Follow(0, MyApplication.user.getId(), userTieziInfo.getUserId(), new Date(System.currentTimeMillis()))).enqueue(new Callback<com.example.goodpet.bean.ResponseBody<Object>>() {
                @Override
                public void onResponse(Call<com.example.goodpet.bean.ResponseBody<Object>> call, Response<com.example.goodpet.bean.ResponseBody<Object>> response) {
                    com.example.goodpet.bean.ResponseBody<Object> body = response.body();
                    if (body!=null){
                        int code = body.getCode();
                        if (code==200){
                            btnTieziInfoFocus.setText("已关注");
                            userTieziInfo.setFoucs(true);

                            Intent intent = new Intent();
                            intent.putExtra("info",userTieziInfo);
                            intent.putExtra("position",POSITION);

                            setResult(RESULT_OK,intent);
                        }else if (code==500){
                            UIUtils.toast("服务器发生错误",false);
                        }
                    }
                }

                @Override
                public void onFailure(Call<com.example.goodpet.bean.ResponseBody<Object>> call, Throwable t) {
                    UIUtils.toast("连接服务器失败",false);
                }
            });
        }
    }

    /**
     * 初始化收藏点击事件的监听
     */
    private void initCollectClickListener() {
        //记得更新数据库
        homeService.updateUserTieziCollect(MyApplication.user.getId(),userTieziInfo.getTieziId())
                .enqueue(new Callback<ResponseBody<Boolean>>() {
                    @Override
                    public void onResponse(Call<ResponseBody<Boolean>> call, Response<ResponseBody<Boolean>> response) {
                        ResponseBody<Boolean> body1 = response.body();
                        if(body1.getCode()==200){
                            Boolean data1 = body1.getData();
                            //收藏成功
                            if(data1){
                                //本来点赞了，再次点击取消点赞
                                if(userTieziInfo.isCollect()){
                                    tieziCollect.setImageDrawable(getDrawable(R.drawable.collection));
                                    userTieziInfo.setCollectNum(userTieziInfo.getCollectNum()-1);
                                }else{
                                    //本来没点赞，再次点击点赞
                                    tieziCollect.setImageDrawable(getDrawable(R.drawable.collection_al));
                                    userTieziInfo.setCollectNum(userTieziInfo.getCollectNum()+1);
                                }
                                userTieziInfo.setCollect(!userTieziInfo.isCollect());
                                Intent intent = new Intent();
                                intent.putExtra("info",userTieziInfo);
                                intent.putExtra("position",POSITION);

                                setResult(RESULT_OK,intent);
                                //更新显示的数量
                                tieziCollectNumber.setText(String.valueOf(userTieziInfo.getCollectNum()));
                            }else{
                                UIUtils.toast("收藏失败",false);
                            }
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody<Boolean>> call, Throwable t) {
                        UIUtils.toast("网络通信失败，点赞失败",false);

                    }
                });

    }

    /**
     * 参初始化点赞点击事件的监听
     */
    private void initLikeClickListener() {
//记得更新数据库
        homeService.updateUserLike(MyApplication.user.getId(), userTieziInfo.getTieziId())
                .enqueue(new Callback<ResponseBody<Boolean>>() {
                    @Override
                    public void onResponse(Call<ResponseBody<Boolean>> call, Response<ResponseBody<Boolean>> response) {
                        ResponseBody<Boolean> body1 = response.body();
                        if(body1.getCode()==200){
                            Boolean data1 = body1.getData();
                            //点赞成功
                            if(data1){
                                //本来点赞了，再次点击取消点赞

                                if(userTieziInfo.isLike()){
                                    tieziLike.setImageDrawable(getDrawable(R.drawable.like48));
                                    userTieziInfo.setLikeNum(userTieziInfo.getLikeNum()-1);
                                }else{
                                    //本来没点赞，再次点击点赞
                                    tieziLike.setImageDrawable(getDrawable(R.drawable.like32_al));
                                    userTieziInfo.setLikeNum(userTieziInfo.getLikeNum()+1);
                                }
                                userTieziInfo.setLike(!userTieziInfo.isLike());
                                Intent intent = new Intent();
                                intent.putExtra("info",userTieziInfo);
                                intent.putExtra("position",POSITION);

                                setResult(RESULT_OK,intent);
                                //更新显示的数量
                                tieziLikeNumber.setText(String.valueOf(userTieziInfo.getLikeNum()));
                            }else{
                                UIUtils.toast("点赞失败",false);
                            }
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody<Boolean>> call, Throwable t) {
                        UIUtils.toast("网络通信失败，点赞失败",false);

                    }
                });

    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    private void initData() {

        //初始化帖子照片
        initTieziImage();
        //初始化发布者信息
        Glide.with(TieziInfoActivity.this)
                .load(Constants.BASE_URL_IMAGE+userTieziInfo.getPortrait())
                .into(ivTieziInfoReleasePortrait);

        tvTieziInfoReleaseUser.setText(userTieziInfo.getNickname());
        //初始化帖子信息
        tvTieziInfoDesc.setText(userTieziInfo.getContent());
        tvTieziInfoTime.setText(userTieziInfo.getPostdate());
        //初始化数量
        tieziLikeNumber.setText(String.valueOf( userTieziInfo.getLikeNum()));
        tieziCollectNumber.setText(String.valueOf( userTieziInfo.getCollectNum()));
        tieziLiuyanNumber.setText(String.valueOf( userTieziInfo.getMessageNum()));

//        Log.e(TAG, "initData: "+userTieziInfo.isLike() );
        //登录用户是否点赞
        if(userTieziInfo.isLike()){
            tieziLike.setImageDrawable(getDrawable(R.drawable.like32_al));
        }
        //登录用户是否收藏
        if(userTieziInfo.isCollect()){
            tieziCollect.setImageDrawable(getDrawable(R.drawable.collection_al));
        }
        //登录用户是否关注贴主
        if(userTieziInfo.isFoucs()){
            btnTieziInfoFocus.setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);
            btnTieziInfoFocus.setText("取消关注");
            btnTieziInfoFocus.setTextColor(getColor(R.color.gray));
        }

        //初始化更多信息
        initMore();


    }

    private void initMore() {

        homeService.selectAllUserTieziInfo(seed,MyApplication.user.getId(),1)
                .enqueue(new Callback<ResponseBody<List<UserTieziInfo>>>() {
                    @Override
                    public void onResponse(Call<ResponseBody<List<UserTieziInfo>>> call, Response<ResponseBody<List<UserTieziInfo>>> response) {
                        ResponseBody<List<UserTieziInfo>> body = response.body();
                        if(body.getCode()==200){
                            userTieziInfos = body.getData();/**
                             * 鸡肋的在更多页面去除当前页面显示的宠物信息
                             */
                            for (int i = 0; i < userTieziInfos.size(); i++) {
                                if (userTieziInfos.get(i).getTieziId() == userTieziInfo.getTieziId()) {
                                    userTieziInfos.remove(i);
                                    break;
                                }
                            }
                            initVlayout();
                        }else{
                            UIUtils.toast("获取更多失败",false);
                        }
                    }

                    private void initVlayout() {
                        //1.设置总布局管理器
                        layoutManager = new VirtualLayoutManager(TieziInfoActivity.this);
                        rvTieziInfoMore.setLayoutManager(layoutManager);
                        //2.设置回收池大小（相同类型的View可以复用，防止多次创建ItemView）
                        RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
                        viewPool.setMaxRecycledViews(0, 10);
                        rvTieziInfoMore.setRecycledViewPool(viewPool);
                        //3.逐个设置子模块适配器
                        initAdapter();

                        //4.设置总适配器
                        DelegateAdapter mainAdapter = new DelegateAdapter(layoutManager, true);
                        mainAdapter.setAdapters(subAdapters);
                        rvTieziInfoMore.setAdapter(mainAdapter);
                    }

                    private void initAdapter() {
                        /**
                         * 设置更多页面的适配器
                         */

                        StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(2, 10);

                        CommunityRecyclerViewAdapter adapter = new CommunityRecyclerViewAdapter(TieziInfoActivity.this, userTieziInfos,TieziInfoActivity.this);
                        LoadMoreWrapper loadMoreWrapper = new LoadMoreWrapper(adapter){
                            @Override
                            public LayoutHelper onCreateLayoutHelper() {
                                return helper;
                            }
                        };
//        rvParent.setAdapter(loadMoreWrapper);
                        subAdapters.add(loadMoreWrapper);


                        rvTieziInfoMore.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
                            @Override
                            public void onLoadMore() {
                                loadMoreWrapper.setLoadState(loadMoreWrapper.LOADING);
                                homeService.selectAllUserTieziInfo(seed,MyApplication.user.getId(),++loadMoreWrapper.page)
                                        .enqueue(new Callback<ResponseBody<List<UserTieziInfo>>>() {
                                            @Override
                                            public void onResponse(Call<ResponseBody<List<UserTieziInfo>>> call, Response<ResponseBody<List<UserTieziInfo>>> response) {
                                                ResponseBody<List<UserTieziInfo>> body = response.body();
                                                if(body.getCode()==200){
                                                    List<UserTieziInfo> data = body.getData();
//                                   Log.e(TAG, "onResponse: "+data1);
                                                    userTieziInfos.addAll(data);
                                                    loadMoreWrapper.setLoadState(loadMoreWrapper.LOADING_COMPLETE);
                                                }else if (body.getCode()==404){
                                                    loadMoreWrapper.setLoadState(loadMoreWrapper.LOADING_END);
                                                }
                                            }

                                            @Override
                                            public void onFailure(Call<ResponseBody<List<UserTieziInfo>>> call, Throwable t) {
                                                Log.e(TAG, "onFailure: "+t.getMessage());
                                                UIUtils.toast("连接服务器失败",false);
                                            }
                                        });
                            }
                        });
                    }

                    @Override
                    public void onFailure(Call<ResponseBody<List<UserTieziInfo>>> call, Throwable t) {
                        UIUtils.toast("连接服务器失败",false);
                    }
                });


    }

//    /**
//     * 初始化收藏图标
//     */
//    private void initCollect() {
//        retrofit= RetrofitSingleton.getRetrofitConstance();
//        homeService=retrofit.create(HomeService.class);
//        homeService.tieziIsCollect((int)userTieziInfo.getUserId(),(int)userTieziInfo.getTieziId())
//                .enqueue(new Callback<ResponseBody<Boolean>>() {
//                    @Override
//                    public void onResponse(Call<ResponseBody<Boolean>> call, Response<ResponseBody<Boolean>> response) {
//                        ResponseBody<Boolean> body = response.body();
//                        if(body.getCode()==200){
//                            Boolean data = body.getData();
//                            //如果用户已经收藏了该页面
//                            if(data){
//                                Drawable drawable = resources.getDrawable(R.drawable.collection_al);
//                                tieziCollect.setImageDrawable(drawable);
//                            }
//                            userTieziInfo.setCollect(data);
//                            //初始化收藏点击事件的监听
//                            tieziLike.setOnClickListener(TieziInfoActivity.this);
//                            tieziLikeNumber.setOnClickListener(TieziInfoActivity.this);
//                        }else{
//                            UIUtils.toast("收藏信息初始化失败",false);
//                        }
//                    }
//
//                    @Override
//                    public void onFailure(Call<ResponseBody<Boolean>> call, Throwable t) {
//                        UIUtils.toast("连接服务器失败",false);
//                    }
//                });
//
//    }

    private void initTieziImage() {
        LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        PetInfoImageAdapter petInfoImageAdapter = new PetInfoImageAdapter(userTieziInfo.getTieziImage(),this);
        rvTieziInfoImage.setAdapter(petInfoImageAdapter);
        rvTieziInfoImage.setLayoutManager(layoutManager);
    }
    /**
     * 当点击用户信息时才能继续操作的区域时，如果未登录跳转至登录界面
     */
    private void actionToLoginAC() {
        startActivity(new Intent(this, LoginActivity.class));
    }

}